package com.dongdongshop.service.imp;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbSpecificationOptionMapper;
import com.dongdongshop.mapper.TbTypeTemplateMapper;
import com.dongdongshop.pojo.TbSpecificationOption;
import com.dongdongshop.pojo.TbTypeTemplate;
import com.dongdongshop.service.TemplatesService;
import com.dongdongshop.util.PageBean;

import javax.annotation.Resource;
import java.util.List;

@Service
@org.springframework.stereotype.Service
public class TemplatesServiceImpl implements TemplatesService {
    @Resource
    private TbTypeTemplateMapper tbTypeTemplateMapper;
    @Resource
    private TbSpecificationOptionMapper tbSpecificationOptionMapper;

    @Override
    public PageBean<TbTypeTemplate> getinfo(String sname,Integer number,Integer pageSize) {
        PageBean<TbTypeTemplate> b = new PageBean<>();
        b.setPageNum(number);
        b.setPageSize(pageSize);
        b.setTotal(tbTypeTemplateMapper.getinfo(sname).size());
        List<TbTypeTemplate> list = tbTypeTemplateMapper.getByName(b,sname);
        b.setResult(list);
        return b;
    }

    @Override
    public Integer addinfo(TbTypeTemplate t) {
        return tbTypeTemplateMapper.insertSelective(t);
    }

    @Override
    public Integer deleteAll(Long[] ids) {
        return tbTypeTemplateMapper.deleteAll(ids);
    }

    @Override
    public TbTypeTemplate selectById(Long id) {
        return tbTypeTemplateMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer updateinfo(TbTypeTemplate t) {
        return tbTypeTemplateMapper.updateByPrimaryKeySelective(t);
    }

    @Override
    public List<TbTypeTemplate> getAll() {
        return tbTypeTemplateMapper.selectByExample(null);
    }

    @Override
    public TbTypeTemplate toGet2(Long typeId) {
        return tbTypeTemplateMapper.selectByPrimaryKey(typeId);
    }

    @Override
    public List<TbSpecificationOption> listOptionsBySpecId(Long id) {
        return tbSpecificationOptionMapper.getinfo(id);
    }
}
